Texture2D shaderTexture;
SamplerState SampleType;

cbuffer LightBuffer
{
	float4 ambientColor;
    float4 diffColor;
    float3 lightDirection;
    float  specularPower;
    float4 specularColor;
};

struct SDXInput
{
    float4 position      : SV_POSITION;
    float3 normal 		 : NORMAL;
    float2 tex 			 : TEXCOORD0;
    float3 viewDirection : TEXCOORD1;
};



float4 PShader(SDXInput input) : SV_TARGET
{
    float4 tColor;
    float3 lightDir;
    float lightIntensity;
    float4 color = ambientColor;
    float3 reflection;
    float4 specular  = float4(0.0f, 0.0f, 0.0f, 0.0f);



    tColor = shaderTexture.Sample(SampleType, input.tex);

    lightDir = -lightDirection;
    lightIntensity = saturate(dot(input.normal, lightDir));

    if(lightIntensity > 0.0f)
    {
        color += (diffColor * lightIntensity);
        color = saturate(color);
        reflection = normalize(2 * lightIntensity * input.normal - lightDir);
        specular   = pow(saturate(dot(reflection, input.viewDirection)), specularPower);
    }

    color = (saturate(color)  * tColor);
	color = color * tColor;
	color = saturate(color + specular);
    return color;
}
